<?php
require_once('../../../../init.php');

LogPay::log_file("商户后台回调地址-notifyurl.php:\r\n".print_pre($_POST));
/**
 * 商户后台回调地址,查看返回信号是否交易成功
 */
if (Payment_Sheng::current()->returnSign())
{
    /*支付成功*/
    $oid=$_POST['OrderNo'];
    $fee=$_POST['TransAmount'];
    /*商家自行检测商家订单状态，避免重复处理，而且请检查fee的值与订单需支付金额是否相同*/
    $order=Order::get_one("order_no=".$oid);
    if ($order){
        $order_fee=sprintf("%01.2f",is_numeric($order->final_amount)?$order->final_amount:0);
        if ($order_fee==$fee){
            $order->pay_status=EnumPayStatus::SUCC;
            $order->update();
            LogPay::log_file("支付成功，订单号:$oid支付成功");
            //创建订单日志
            $orderlog=new Orderlog();
            $orderlog->order_no=$order->order_no;
            $orderlog->order_id=$order->order_id;
            $admin_alipay=Admin::shengpay();//支付宝的管理员标识
            $orderlog->admin_id=$admin_alipay->admin_id;
            $orderlog->operater=$admin_alipay->realname;
            $orderlog->orderAction=EnumOrderAction::PAY;
            $orderlog->result=EnumResult::SUCC;
            $orderlog->intro="客户通过盛付通付款";
            $orderlog->save();
            //创建支付日志
            $paylog=new Paylog();
            $paylog->order_no=$order->order_no;
            $paylog->order_id=$order->order_id;
            $admin_alipay=Admin::shengpay();//支付宝的管理员标识
            $paylog->admin_id=$admin_alipay->admin_id;
            $paylog->operater=$admin_alipay->realname;
            $paylog->pay_type=$order->pay_type;
            $paylog->amount=$order->final_amount;
            $paylog->payAction=EnumPayAction::UNPAY;
            $paylog->result=EnumResult::SUCC;
            $paylog->intro="客户通过盛付通付款";
            $paylog->save();
            echo 'OK';
            die();
        }
    }
    echo 'Error';
}else{
    echo 'Error';
}

?>
